package com.atguigu.controller;

import com.atguigu.dto.system.AssginRoleDto;
import com.atguigu.dto.system.SysUserDto;
import com.atguigu.entity.system.SysUser;
import com.atguigu.service.SysUserService;
import com.atguigu.vo.common.Result;
import com.atguigu.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户管理")
@RestController
@RequestMapping("/system/user")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @Operation(summary = "分页")
    @GetMapping("/page/{current}/{limit}")
    public Result page(@PathVariable Integer current, @PathVariable Integer limit, SysUserDto sysUserDto) {
        PageInfo<SysUser> pageInfo = sysUserService.page(current, limit, sysUserDto);
        return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "新增")
    @PostMapping("/submit")
    public Result submit(@RequestBody SysUser sysUser) {
        sysUserService.submit(sysUser);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除")
    @GetMapping("/remove")
    public Result remove(@RequestParam long userId) {
        sysUserService.remove(userId);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改")
    @PostMapping("/update")
    public Result update(@RequestBody SysUser sysUser) {
        sysUserService.update(sysUser);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "分配角色")
    @PostMapping("doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto) {
        sysUserService.doAssign(assginRoleDto);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
